package com.lixixi.tingshu.account.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lixixi.tingshu.account.service.UserAccountService;
import com.lixixi.tingshu.common.anno.NeedLogin;
import com.lixixi.tingshu.common.result.Result;
import com.lixixi.tingshu.common.util.AuthContextHolder;
import com.lixixi.tingshu.model.account.UserAccount;
import com.lixixi.tingshu.vo.account.AccountLockVo;
import com.lixixi.tingshu.vo.order.OrderInfoVo;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/api/account/userAccount/")
public class UserAccountApiController {

	@Autowired
	UserAccountService userAccountService;

//	http://127.0.0.1/api/account/userAccount/getAvailableAmount
	@GetMapping("/getAvailableAmount")
	@NeedLogin
	Result<BigDecimal> getAvailableAmount(){
		LambdaQueryWrapper<UserAccount> wrapper = new LambdaQueryWrapper<UserAccount>()
				.eq(UserAccount::getUserId, AuthContextHolder.getUserId())
				.select(UserAccount::getAvailableAmount);
		UserAccount userAccount = userAccountService.getOne(wrapper);
		return Result.ok(userAccount.getAvailableAmount());
	}

	@PostMapping("/checkAndLock")
	@NeedLogin
	Result checkAndLock(@RequestBody AccountLockVo accountLockVo){
		return userAccountService.checkAndLock(accountLockVo);
	}


}
